<link href="<?php echo site_url() ?>assets/css/nhatnv.css" media="all" rel="stylesheet" type="text/css" />
<link href="<?php echo site_url() ?>assets/chosen_v1.4.2/chosen.css" media="all" rel="stylesheet" type="text/css" />

<div id="sidetabs_body_container">
    <div id="table_area" style="">
        <div id="action_bar" class="action_bar">
            <div id="detail_header">
                <table class="lean">
                    <tbody>
                        <tr>
                            <td class="s3status">
                                <div class="pcni ">
                                    <?php echo $fview->ClassOnOff($data->time_update); ?> 
                                </div>
                            </td>
                            <td>
                                <h1 class="db s3name"><?php echo $data->namedevice; ?></h1>
                            </td>
                        </tr>
                    </tbody>
                </table>
                <div id="next_prev_links">
                    <?php if ($data->previours != null): ?>
                        <a id="prev_ap" href="<?php echo site_url() . 'edit-device?id=' . md5($data->previours) ?>" style="display: inline;">‹ Previous access point</a>
                    <?php endif; ?>
                    <?php if ($data->previours != null && $data->next != null): ?>
                        <span class="barsep" style="display: inline;">|</span>
                    <?php endif; ?>
                    <?php if ($data->next != null): ?>
                        <a id="next_ap" href="<?php echo site_url() . 'edit-device?id=' . md5($data->next) ?>" style="display: inline;">Next access point ›</a>
                    <?php endif; ?>
                </div>
                <hr class="s3" style="clear:both">
            </div>
        </div>
        <div id="detail_area">
            <div id="details_wrapper" class="hideport3">
                <div class="column-50">
                    <div id="node_info_details" style="width: 100%">
                        <ul id="status_alerts" class="alerts status_alerts status_alerts_container" style="display: none;">  </ul>
                        <div id="formedit" style="display: <?php if (!in_array($submit, array(null, '', '0'))): ?>block<?php else: ?>none<?php endif; ?>">
                            <?php if (@$error || @$zero): ?>
                                <style>
                                    .notice_explanation p{  margin: 0px;}
                                    .notice_explanation{ min-height: 20px; height: auto !important;float: left;}
                                </style>
                                <div class="notice_explanation bad">
                                    <?php if (@$error): ?>
                                        <?php echo $error ?>
                                    <?php endif; ?>
                                </div>

                            <?php else: ?>
                                <?php if (in_array(@$status, array('Cập nhật thành công.'))): ?>
                                    <script>
                                        alert('Cập nhật thành công');
                                        window.location = '<?php echo site_url() . 'edit-device.html?id=' . $id ?>';
                                    </script>
                                <?php endif; ?>
                            <?php endif; ?>
                            <?php
                            $att = array('class' => 's3edit', 'enctype' => 'multipart/form-data');
                            echo form_open('edit-device?id=' . $id . '&submit=1', $att);
                            ?>
                            <input name="id" value="<?php echo $id ?>" type="hidden"/>
                            <p>
                                <label>Tên thiết bị <b style="color: red">(*)</b></label>
                                <span>
                                    <input class="w99 <?php echo (form_error('namedevice') ? 'textInputError' : '') ?>" id="namedevice" name="namedevice" type="text" value="<?php echo $data->namedevice ?>">
                                </span>
                            </p>
                            <?php echo form_error('namedevice'); ?>
                            <p>
                                <label>Mac thiết bị <b style="color: red">(*)</b></label>
                                <span>
                                    <input class="w99 <?php echo (form_error('mac') ? 'textInputError' : '') ?>" id="mac" name="mac" type="text" value="<?php echo $data->mac ?>">
                                </span>
                            </p>
                            <?php echo form_error('mac'); ?>
                            <p>
                                <label>Nasid thiết bị <b style="color: red">(*)</b></label>
                                <span>
                                    <input class="w99 <?php echo (form_error('nasid') ? 'textInputError' : '') ?>" id="nasid" name="nasid" type="text" value="<?php echo $data->nasid ?>">
                                </span>
                            </p>
                            <?php echo form_error('nasid'); ?>
                            <p>
                                <label>UAMSERVER <b style="color: red">(*)</b></label>
                                <span>
                                    <input class="w99 <?php echo (form_error('HS_UAMFORMAT') ? 'textInputError' : '') ?>" id="HS_UAMFORMAT" name="HS_UAMFORMAT" type="text" value="<?php echo $data->HS_UAMFORMAT ?>">
                                </span>
                            </p>
                            <?php echo form_error('HS_UAMFORMAT'); ?>
                            <p>
                                <label>UAMHOMEPAGE <b style="color: red">(*)</b></label>
                                <span>
                                    <input class="w99 <?php echo (form_error('HS_UAMHOMEPAGE') ? 'textInputError' : '') ?>" id="HS_UAMHOMEPAGE" name="HS_UAMHOMEPAGE" type="text" value="<?php echo $data->HS_UAMHOMEPAGE ?>">
                                </span>
                            </p>
                            <?php echo form_error('HS_UAMHOMEPAGE'); ?>
                            <p>
                                <label style="    font-size: 11px;">DEFSESSIONTIMEOUT <b style="color: red">(*)</b></label>
                                <span>
                                    <input class="w99 <?php echo (form_error('HS_DEFSESSIONTIMEOUT') ? 'textInputError' : '') ?>" id="HS_DEFSESSIONTIMEOUT" name="HS_DEFSESSIONTIMEOUT" type="text" value="<?php echo $data->HS_DEFSESSIONTIMEOUT ?>">
                                </span>
                            </p>
                            <?php echo form_error('HS_DEFSESSIONTIMEOUT'); ?>
                            <p>
                                <label>DEFIDLETIMEOUT <b style="color: red">(*)</b></label>
                                <span>
                                    <input class="w99 <?php echo (form_error('HS_DEFIDLETIMEOUT') ? 'textInputError' : '') ?>" id="HS_DEFIDLETIMEOUT" name="HS_DEFIDLETIMEOUT" type="text" value="<?php echo $data->HS_DEFIDLETIMEOUT ?>">
                                </span>
                            </p>
                            <?php echo form_error('HS_DEFIDLETIMEOUT'); ?>
                            <p>
                                <label>Version hotspot <b style="color: red">(*)</b></label>
                                <span>
                                    <input class="w99 <?php echo (form_error('version') ? 'textInputError' : '') ?>" id="version" name="version" type="text" value="<?php echo $data->version ?>">
                                </span>
                            </p>
                            <?php echo form_error('version'); ?>
                            <p>
                                <label>Nhóm mạng <b style="color: red">(*)</b></label>
                                <span>
                                    <?php if($this->session->userdata('level') == 3):?>
                                    <?php echo $fview->returntextSelect($networkgroup, set_value('network_group') ? $this->input->post('network_group') : @$data->network_group, (form_error('network_group') ? 'textselectError' : ""), 'network_group', 'network_group', 0, 'style="width: 100%;"'); ?>
                                    <?php else:?>
                                    <?php echo $fview->selectOption($networkgroup, set_value('network_group') ? $this->input->post('network_group') : @$data->network_group, (form_error('network_group') ? 'textselectError' : ""), 'network_group', 'network_group', 0, 'style="width: 100%;"'); ?>
                                    <?php endif;?>
                                </span>
                            </p>
                            <?php echo form_error('network_group'); ?>
                            <p>
                                <label>Địa điểm <b style="color: red">(*)</b></label>
                                <span>
                                    <?php if($this->session->userdata('level') == 3):?>
                                    <?php echo $fview->returntextSelect($place, set_value('place') ? set_value('place') : @$data->id_address, (form_error('place') ? 'chosen-select-width textselectError' : "chosen-select-width"), 'place', 'place', 0, 'tabindex="-1" style="display: none;" data-placeholder="Nhập địa điểm cần tìm" '); ?>
                                    <?php else:?>
                                    <?php echo $fview->selectOption($place, set_value('place') ? set_value('place') : @$data->id_address, (form_error('place') ? 'chosen-select-width textselectError' : "chosen-select-width"), 'place', 'place', 0, 'tabindex="-1" style="display: none;" data-placeholder="Nhập địa điểm cần tìm" '); ?>
                                    <?php endif;?>
                                </span>
                            </p>
                            <?php echo form_error('place'); ?>
                            <p>
                                <label>File cấu hình tùy chỉnh
                                    <br/>( file.zip )</label>
                                <span>
                                    <input type="file" class="w99" id="fileconfig" name="fileconfig" />
                                    <br /><br /><b>Link: </b>
                                    <a href="<?php echo site_url() . 'public/' . $data->linkupdate ?>">
                                        <?php echo $data->linkupdate ?>
                                    </a>
                                </span>
                            </p>

                            <p>
                                <label>Trạng thái</label>
                                <span>
                                    <?php echo $fview->selectOption(array('1' => 'Hoạt động', '0' => 'Không hoạt động'), @$data->active ? @$data->active : $this->input->post('active'), 'form-control' . (form_error('active') ? ' textselectError' : ""), 'active', 'active', 0, 'style="width: 100%;"'); ?>
                                </span>
                            </p>
                            <?php echo form_error('active'); ?>
                            <p>
                                <label>&nbsp;</label>
                                <span>
                                    <input type="submit" id="saveConfig" value="Lưu lại">
                                    <input type="reset" id="cancelSaveConfig" value="Quay lại">
                                </span>
                            </p>
                            </form>
                        </div>
                        <div id="nodeinfo" class="statusinfo" style="display: <?php if (!in_array($submit, array(null, '', '0'))): ?>none<?php else: ?>block<?php endif; ?>">
                            <table class="s3basic status_table">
                                <tbody>
                                    <tr>
                                        <td colspan="2">
                                            <h2 class="s3">Configuration <span class="barsep">|</span> <a class="s3showing" id="showconfig" style="font-size:small" href="#">Edit&nbsp;configuration</a></h2>
                                        </td>
                                    </tr>
                                    <tr class="base">
                                        <td class="s3l">MAC address:</td>
                                        <td class="s3x"><span class="atomic"><?php echo $data->mac ?></span></td>
                                    </tr>
                                    <tr class="base">
                                        <td class="s3l">Nasid address:</td>
                                        <td class="s3x"><span class="atomic"><?php echo $data->nasid ?></span></td>
                                    </tr>

                                    <tr class="base s3tr_address allow_wrap">
                                        <td class="s3l">Address:</td>
                                        <td class="s3x"><span class="atomic"><?php echo $data->address ?></span></td>
                                    </tr>
                                    <tr class="base s3tr_address allow_wrap">
                                        <td class="s3l">Version:</td>
                                        <td class="s3x">
                                            <span class="atomic">
                                                <?php echo $data->version ?>
                                            </span>
                                        </td>
                                    </tr>
                                    <tr class="base s3tr_address allow_wrap">
                                        <td class="s3l">File Config:</td>
                                        <td class="s3x">
                                            <span class="atomic">
                                                <a href="<?php echo site_url() . 'public/' . $data->linkupdate ?>">
                                                    <?php echo $data->linkupdate ?>
                                                </a>
                                            </span>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                        <div id="statusinfos" class="statusinfo" style="display: <?php if (!in_array($submit, array(null, '', '0'))): ?>none<?php else: ?>block<?php endif; ?>">
                            <table class="s3basic status_table">
                                <tbody>
                                    <tr class="base">
                                    </tr>
                                    <tr class="base">
                                        <td colspan="2">
                                            <h2 style="padding-top: 0.5ex" class="s3">Status</h2>
                                        </td>
                                    </tr>
                                    <tr class="base" id="status_channel_status_row" style="display:none;">
                                        <td class="s3l">Channel:</td>
                                        <td class="s3x" id="status_channel_status"></td>
                                    </tr>
                                    <tr class="base" id="status_inet_rows">
                                        <td class="s3l">         
                                            Access point info      
                                        </td>
                                        <td class="s3x">
                                            <div>           
                                                <a href="javascript: void(0)" id="_showifconfig">Detail</a>         
                                            </div>
                                        </td>
                                    </tr>
                                    <tr style="display: none" id="showifconfig">
                                        <td colspan="2" style="padding-left: 50px;">
                                            <?php
                                            echo "<pre>";
                                            echo $data->info_network_ap
                                            ?>
                                            <p><button style="float: right; " id="_hideifconfig">Đóng lại</button></p>
                                        </td>
                                    </tr>
                                    <tr class="base" id="status_inet_rows">
                                        <td class="s3l">         
                                            Last Online      
                                        </td>
                                        <td class="s3x">
                                            <div>           
                                                <?php echo $data->date_update ? $data->date_update : 'Unknow' ?>         
                                            </div>
                                        </td>
                                    </tr>
                                    <tr class="base" id="status_inet_rows">
                                        <td class="s3l">         
                                            Access point Online      
                                        </td>
                                        <td class="s3x">
                                            <div>           
                                                <?php echo $fview->ClassOnOff($data->time_update); ?>          
                                            </div>
                                        </td>
                                    </tr>
                                    <tr class="base" id="status_event_log_row">
                                        <td class="s3l">History:</td>
                                        <td class="s3x" id="status_event_log"><a href="javascript: void(0)" class="nowrap add-note">Add note</a></td>
                                    </tr>
                                    <tr class="base" id="form_add_note" style="display: none;">
                                        <td class="s3l">&nbsp;</td>
                                        <td class="s3x" id="status_event_log">
                                            <p>
                                                <textarea style="  width: 99%;" id="contentnote" name="contentnote" rows="3"></textarea>
                                            </p>
                                            <p class="addNoteNotification" style="  margin: 0px;"></p>
                                            <p>
                                                <button data-id="<?php echo $id ?>" id="addNote">Lưu lại</button>
                                                <button id="cancelAddNote">Hủy bỏ</button>
                                            </p>
                                        </td>
                                    </tr>

                                </tbody>
                            </table>
                        </div>
                    </div>

                    <div class="hideport3" style="  float: left;width: 100%;margin-top: 20px;">
                        <h2 class="s3" style="margin-top: 7px">Ports&nbsp;</h2>
                        <hr style="margin-top: -2px">
                    </div>

                    <table class="switchportstable">
                        <tbody>
                            <?php if (!in_array($data->info_port, array(null, '', '0'))): ?>
                                <tr class="labels">
                                    <td class="spacer"></td>
                                    <td>Wan</td>
                                    <td>0</td>
                                    <td>1</td>
                                    <td>2</td>
                                    <td>3</td>
                                </tr>
                                <tr class="top">
                                    <td class="spacer"></td>
                                    <?php
                                    $jsonport = explode('|', $data->info_port);
                                    $count = sizeof($jsonport);
                                    for ($i = 0; $i < $count; $i++):
                                        ?>

                                        <td id="port_1" class="switchport <?php echo $jsonport[$i]; ?>"></td>
                                    <?php endfor; ?>
                                </tr>
                            <?php else: ?>
                                <tr class="labels">
                                    <td class="spacer"></td>
                                    <td>Wan</td>
                                    <td>0</td>
                                    <td>1</td>
                                    <td>2</td>
                                    <td>3</td>
                                </tr>
                                <tr class="top">
                                    <td class="spacer"></td>
                                    <td id="port_1" class="switchport"></td>
                                    <td id="port_1" class="switchport"></td>
                                    <td id="port_1" class="switchport"></td>
                                    <td id="port_1" class="switchport"></td>
                                    <td id="port_1" class="switchport"></td>
                                </tr>
                            <?php endif; ?>
                        </tbody>
                    </table>
                </div>
                <div class="column-50">
                    <div class="map" id="googleMap" style="margin: 0px 0px 0px 50px;height: 250px;">

                    </div>

                </div>

                <div style="float: left;width: 100%">
                    <h1>Chức năng khác</h1>
                    <table id="live_toolbox" class="hideport3" cellspacing="0" cellpadding="0">
                        <colgroup>
                            <col width="155px">
                        </colgroup>
                        <tbody>
                            <tr>
                                <td id="lt_tools_cell">
                                    <div id="lt_tools_container">
                                        <div class="tool_header reset-device" data-id="<?php echo $id ?>">
                                            <span class="reset_lbl">Reset Access point</span>
                                        </div>
                                        <div class="tool_header current_tool reset-statistic" data-id="<?php echo $id ?>">
                                            <span class="refresh_lbl">Refresh statistic</span>
                                        </div>
                                        <div class="tool_header history-device" data-id="<?php echo $id ?>">
                                            <span class="history_lbl">History log</span>
                                        </div>
                                        <div class="tool_header" onclick="window.location = '<?php echo site_url() . 'customer?id=' . $id ?>'">
                                            <span>Clients</span>
                                        </div>
                                    </div>
                                </td>
                                <td id="lt_tools_display" style="vertical-align: top; border-top:1px solid #BBB;">
                                    <?php
                                    $down = "";
                                    $up = "";
                                    $time = "";
                                    $data_statistic = $data->statistic;
                                    foreach ($data_statistic AS $el => $le) {

                                        $down .= ',' . $le->indata / 1048576;
                                        $up .= ',' . $le->outdata / 1048576;
                                        $time .= ",'" . $le->times . "'";
                                    }

                                    $_down = substr($down, 1);
                                    $_up = substr($up, 1);
                                    $_time = substr($time, 1);
                                    ?>
                                    <div id="lt_display_container" class="id_form_device">

                                        <script src="<?php echo site_url() . 'assets/js/highcharts.js' ?>"></script>
                                        <script src="<?php echo site_url() . 'assets/js/exporting.js' ?>"></script>
                                        <script>
                                            $(function () {


                                                $('#container').highcharts({
                                                    chart: {
                                                        type: 'area'
                                                    },
                                                    title: {
                                                        text: 'Enthernet Traffic'
                                                    },
                                                    yAxis: {
                                                        title: {
                                                            text: 'GB'
                                                        },
                                                        labels: {
                                                            formatter: function () {
                                                                return this.value / 1000;
                                                            }
                                                        }
                                                    }, plotOptions: {
                                                        area: {
                                                            stacking: 'normal',
                                                            lineColor: '#666666',
                                                            lineWidth: 1,
                                                            marker: {
                                                                lineWidth: 1,
                                                                lineColor: '#666666'
                                                            }
                                                        }
                                                    }, xAxis: {
                                                        categories: [<?php echo $_time ?>],
                                                        plotBands: [{// visualize the weekend
                                                                from: 4.5,
                                                                to: 6.5,
                                                                color: 'rgba(68, 170, 213, .2)'
                                                            }]
                                                    },
                                                    tooltip: {
                                                        pointFormat: '{point.y:,.0f} MB'
                                                    },
                                                    series: [{
                                                            name: 'Traffic Download',
                                                            data: [<?php echo $_down; ?>]
                                                        },
                                                        {
                                                            name: 'Traffic Upload',
                                                            data: [<?php echo $_up; ?>]
                                                        }]
                                                });
                                            });</script>
                                        <div id="container" style="min-width: 310px; height: 300px; margin: 0 auto"></div>
                                    </div>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<style>
    #pagination{
    }
    #pagination a{
        padding: 5px 10px;
        margin: 10px 2px;
        border: 1px solid #CCC;
        background: #6E6E6E;
        color: #FFF;
    }
    #pagination strong{
        padding: 5px 10px;
        margin: 10px 2px;
        border: 1px solid #CCC;
        background-color: #FFF;
    }
    .chosen-container-single, .chosen-single span{
        width: 100% !important
    }
    .show-error-select-chosen{
            border: 1px solid #DE0000 !important;
            color: #DE0000 !important;
        }
    .chosen-single span {
        float: left !important;
    }
    .row-error{
        margin: 0px;
        color: #DE0000;
    }
</style>
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script src="http://maps.googleapis.com/maps/api/js"></script>
<script src="<?php echo site_url() ?>assets/chosen_v1.4.2/chosen.jquery.js" type="text/javascript"></script>
<script type="text/javascript">
                                          var config = {
                                              '.chosen-select': {},
                                              '.chosen-select-deselect': {allow_single_deselect: true},
                                              '.chosen-select-no-single': {disable_search_threshold: 10},
                                              '.chosen-select-no-results': {no_results_text: 'Oops, nothing found!'},
                                              '.chosen-select-width': {width: "95%"}
                                          }
                                          for (var selector in config) {
                                              $(selector).chosen(config[selector]);
                                          }

                                          function setMenuTool(name)
                                          {
                                              $('.reset-statistic').removeClass('current_tool');
                                              $('.history-device').removeClass('current_tool');
                                              $('.' + name).addClass('current_tool');
                                          }
                                          $(function ()
                                          {
                                              $('#_showifconfig').click(function ()
                                              {
                                                  $('#showifconfig').show();
                                              });
                                              $('#_hideifconfig').click(function ()
                                              {
                                                  $('#showifconfig').hide();
                                              });

                                              $('#showconfig').click(function ()
                                              {
                                                  $('#formedit').show();
                                                  $('.statusinfo').hide();
                                              });

                                              $('#cancelSaveConfig').click(function ()
                                              {
                                                  $('#formedit').hide();
                                                  $('.statusinfo').show();
                                              });

                                              var addnotedevice = 0;
                                              $('#addNote').click(function ()
                                              {
                                                  if (addnotedevice == 0)
                                                  {
                                                      var contentComment = $('#contentnote').val();
                                                      if ($.inArray(contentComment, [null, "", '0']) !== -1)
                                                      {
                                                          alert('Vui lòng nhập vào nội dung');
                                                          return false;
                                                      }

                                                      addnotedevice = 1;
                                                      $('#addNote').html('Xin chờ...');
                                                      var ids = $(this).data('id');
                                                      $.ajax({
                                                          type: 'get',
                                                          url: '<?php echo site_url() ?>add-note-device-ajax',
                                                          data: ({id: ids, content: contentComment}),
                                                          success: function (data)
                                                          {
                                                              addnotedevice = 0;
                                                              $('.addNoteNotification').html('<b style="color: green">Thêm mới lịch sử thành công</b>');
                                                              setTimeout(function ()
                                                              {
                                                                  $('.addNoteNotification').html('');
                                                              }, 2000);
                                                              $('#addNote').html('Lưu lại');
                                                              $('#contentnote').val('');
                                                              if (history_device_select == 1)
                                                              {
                                                                  $.ajax({
                                                                      type: 'get',
                                                                      url: '<?php echo site_url() ?>get-history-device-ajax',
                                                                      data: ({id: ids}),
                                                                      success: function (data)
                                                                      {
                                                                          history_device = 0;
                                                                          $('.history_lbl').html('History log');

                                                                          $('.id_form_device').html(data);
                                                                          $("#lt_tools_display").animate({
                                                                              backgroundColor: "#e1efff"
                                                                          }, 50);
                                                                          $("#lt_tools_display").animate({
                                                                              backgroundColor: "#fff"
                                                                          }, 2500);
                                                                          $('.notification_show_history').html('');
                                                                      }
                                                                  });
                                                              }

                                                          }
                                                      });
                                                  }
                                              });

                                              $('.add-note').click(function ()
                                              {
                                                  $('#form_add_note').show();
                                              });

                                              $('#cancelAddNote').click(function ()
                                              {
                                                  $('#contentnote').val('');
                                                  $('#form_add_note').hide();
                                              });

                                              var reset_device = 0;
                                              $('.reset-statistic').click(function ()
                                              {
                                                  if (reset_device == 0)
                                                  {
                                                      setMenuTool('reset-statistic');
                                                      reset_device = 1;
                                                      $('.refresh_lbl').html('Xin chờ...');
                                                      //$('.id_form_device').html('Đang tải lại...');
                                                      var ids = $(this).data('id');
                                                      $.ajax({
                                                          type: 'get',
                                                          url: '<?php echo site_url() ?>get-statistic-device-ajax',
                                                          data: ({id: ids}),
                                                          success: function (data)
                                                          {
                                                              reset_device = 0;
                                                              $('.refresh_lbl').html('Refresh statistic');
                                                              $('.id_form_device').html(data);
                                                          }
                                                      });
                                                  }
                                              });

                                              var history_device = 0;
                                              var history_device_select = 0;
                                              $('.history-device').click(function ()
                                              {
                                                  if (history_device == 0)
                                                  {
                                                      history_device_select = 1;
                                                      setMenuTool('history-device');
                                                      history_device = 1;
                                                      $('.history_lbl').html('Xin chờ...');
                                                      var ids = $(this).data('id');
                                                      $.ajax({
                                                          type: 'get',
                                                          url: '<?php echo site_url() ?>get-history-device-ajax',
                                                          data: ({id: ids}),
                                                          success: function (data)
                                                          {
                                                              history_device = 0;
                                                              $('.history_lbl').html('History log');
                                                              $('.id_form_device').html(data);
                                                          }
                                                      });
                                                  }
                                              });

                                              var reset_device = 0;
                                              $('.reset-device').click(function ()
                                              {
                                                  var r = confirm("Bạn có chắc chắn reset lại thiết bị này?\nNếu bạn đồng ý thay đổi, mọi thay đổi sẽ có hiệu lực sau 2 phút.");
                                                  if (r == true) {
                                                      if (reset_device == 0)
                                                      {
                                                          reset_device = 1;
                                                          history_device_select = 0;
                                                          $('.reset_lbl').html('Xin chờ ...');
                                                          var ids = $(this).data('id');
                                                          $.ajax({
                                                              type: 'get',
                                                              url: '<?php echo site_url() ?>reset-device-ajax',
                                                              data: ({id: ids}),
                                                              success: function (data)
                                                              {
                                                                  reset_device = 0
                                                                  $('.reset_lbl').html('Reset Access point');
                                                                  alert('Yêu cầu khởi động lại thiết bị thành công');
                                                              }
                                                          });
                                                      }
                                                  }
                                              });
                                          });
                                          var map;
                                          function setLocation(lat, long, address)
                                          {
                                              var mapProp = {
                                                  center: new google.maps.LatLng(lat, long),
                                                  zoom: 15,
                                                  mapTypeId: google.maps.MapTypeId.ROADMAP
                                              };
                                              map = new google.maps.Map(document.getElementById("googleMap"), mapProp);
                                              var myLatlng = new google.maps.LatLng(lat, long);
                                              var popup = new google.maps.InfoWindow({content: address});
                                              var marker = new google.maps.Marker({position: myLatlng, map: map, html: address, icon: '', animation: google.maps.Animation.DROP});
                                              google.maps.event.addListener(marker, 'mouseover', function (e) {
                                                  popup.setContent(this.html);
                                                  popup.open(map, this);
                                              });
                                              google.maps.event.addListener(marker, 'mouseout', function (e) {
                                                  popup.setContent(this.html);
                                              });
                                          }
                                          function initialize() {
                                              var mapProp = {
                                                  center: new google.maps.LatLng(15.9030623, 105.8066791, 6),
                                                  zoom: 5,
                                                  mapTypeId: google.maps.MapTypeId.ROADMAP
                                              };
                                              map = new google.maps.Map(document.getElementById("googleMap"), mapProp);
                                              setLocation(<?php echo $data->lat ? $data->lat : '15.9030623' ?>, <?php echo $data->long ? $data->long : '105.8066791' ?>, "<?php echo $data->address ?>");
                                          }
                                          google.maps.event.addDomListener(window, 'load', initialize);
                                          $(document).ready(function ()
                                          {

                                              $('#place').on('change', function ()
                                              {
                                                  var id_place = $(this).val();
                                                  $.ajax({
                                                      type: 'get',
                                                      url: '<?php echo site_url('get-map'); ?>',
                                                      data: ({id: id_place}),
                                                      success: function (_data)
                                                      {
                                                          var dc = jQuery.parseJSON(_data);
                                                          setLocation(dc.lat, dc.long, dc.address);
                                                      }
                                                  });
                                              });
                                              $("#province").on('change', function ()
                                              {
                                                  var id_province = $(this).val();
                                                  $("#district_select").html('<input type="text" value="Plz, waitting..." class="form-control" name="">');
                                                  $.ajax({
                                                      type: 'get',
                                                      url: '<?php echo site_url('get-district'); ?>',
                                                      data: ({id: id_province}),
                                                      success: function (_data)
                                                      {
                                                          $("#district_select").html(_data);
                                                      }
                                                  });
                                              });
                                              $('.del_item').click(function () {
                                                  var r = confirm("Bạn có chắc chắn xóa thiết bị này không?");
                                                  if (r == true) {
                                                      window.location = '<?php echo site_url() . 'device?type=delete&id='; ?>' + this.id;
                                                  } else {
                                                      return false;
                                                  }
                                              });
                                          });
                                          
<?php if (form_error('place')): ?>
        $('.chosen-single').addClass('show-error-select-chosen');
<?php endif; ?>
                                          
$(".chosen-select-width").chosen().change(function() {
    $('.chosen-single').removeClass('show-error-select-chosen');
    //$('#' + $(this).val()).show();
});

$('#network_group').on('change', function()
{
   $(this).removeClass('textselectError');
});

$('.w99').on('change', function()
{
    $(this).removeClass('textInputError');
});
</script>